package game.model.request;

import com.google.common.collect.Lists;
import common.model.enums.RecipeProductTypeEnum;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author 米泽鹏
 * @since 2022-3-5 下午 7:25
 */
@Data
public class SaveRecipeRequest {

	/**
	 * 配方主键
	 */
	private Long recipeId;
	/**
	 * 配方名称
	 */
	private String recipeName;
	/**
	 * 产物类型：1-物品 2-建筑<br/>
	 * {@link RecipeProductTypeEnum}
	 */
	private Integer productType;
	/**
	 * 排序
	 */
	private Integer sort;
	/**
	 * 原料
	 */
	@Valid
	@NotEmpty(message = "原料不能为空", groups = {ValidateForBuilding.class})
	private List<Material> materialList = Lists.newArrayList();
	/**
	 * 物品产物
	 */
	@Valid
	@NotEmpty(message = "产物不能为空", groups = {ValidateForItem.class})
	private List<Product> productList = Lists.newArrayList();
	/**
	 * 建筑产物
	 */
	@Valid
	@NotNull(message = "产物不能为空", groups = {ValidateForBuilding.class})
	private BuildingProduct buildingProduct;
	/**
	 * 建筑
	 */
	@Valid
	@NotEmpty(message = "建筑不能为空", groups = {ValidateForItem.class})
	private List<Building> buildingList = Lists.newArrayList();

	/**
	 * 校验用于生产物品的配方
	 */
	public interface ValidateForItem {
	}

	/**
	 * 校验用于生产建筑的配方
	 */
	public interface ValidateForBuilding {
	}

	@Data
	public static class Material {

		@Valid
		@NotNull(message = "物品不能为空", groups = {ValidateForItem.class, ValidateForBuilding.class})
		private MaterialInner item;

		/**
		 * 一次生产过程需要或产出的数量
		 */
		@NotNull(message = "原料的数量（/次）不能为空", groups = {ValidateForItem.class, ValidateForBuilding.class})
		private BigDecimal quantityPerProduction;

		/**
		 * 每分钟需要或产出的数量
		 */
		private BigDecimal quantityPerMinute;

		@Data
		public static class MaterialInner {

			/**
			 * 物品主键
			 */
			@NotNull(message = "物品主键不能为空", groups = {ValidateForItem.class, ValidateForBuilding.class})
			private Long id;

			/**
			 * 物品名称
			 */
			@NotBlank(message = "物品名称不能为空", groups = {ValidateForItem.class, ValidateForBuilding.class})
			private String itemName;

		}

	}

	@Data
	public static class Product {

		@Valid
		@NotNull(message = "物品不能为空", groups = {ValidateForItem.class})
		private ProductInner item;

		/**
		 * 一次生产过程产出的数量
		 */
		@NotNull(message = "产物的数量（/次）不能为空", groups = {ValidateForItem.class})
		private BigDecimal quantityPerProduction;

		/**
		 * 每分钟产出的数量
		 */
		private BigDecimal quantityPerMinute;

		@Data
		public static class ProductInner {

			/**
			 * 物品主键
			 */
			@NotNull(message = "物品主键不能为空", groups = {ValidateForItem.class})
			private Long id;

			/**
			 * 物品名称
			 */
			@NotBlank(message = "物品名称不能为空", groups = {ValidateForItem.class})
			private String itemName;

		}

	}

	@Data
	public static class BuildingProduct {

		/**
		 * 建筑主键
		 */
		@NotNull(message = "建筑主键不能为空", groups = {ValidateForItem.class, ValidateForBuilding.class})
		private Long id;

		/**
		 * 建筑名称
		 */
		@NotBlank(message = "建筑名称不能为空", groups = {ValidateForItem.class, ValidateForBuilding.class})
		private String buildingName;

	}

	@Data
	public static class Building {

		@Valid
		@NotNull(message = "建筑不能为空", groups = {ValidateForItem.class, ValidateForBuilding.class})
		private BuildingInner building;

		@Data
		public static class BuildingInner {

			/**
			 * 建筑主键
			 */
			@NotNull(message = "建筑主键不能为空", groups = {ValidateForItem.class, ValidateForBuilding.class})
			private Long id;

			/**
			 * 建筑名称
			 */
			@NotBlank(message = "建筑名称不能为空", groups = {ValidateForItem.class, ValidateForBuilding.class})
			private String buildingName;

		}

	}

}
